<template>
<div>
  <h1>添加广告</h1>
  <p>图片:<input type="file" id="img"></p>
  <p>跳转地址:<input type="text" v-model="form.jump"></p>
  <p>类型<input type="text" v-model="form.type"></p>
  <button @click="get_jia">添加</button>

  <table border="1">
    <tr>
      <td>图片</td>
      <td>跳转地址</td>
      <td>类型</td>
    </tr>
    <tr v-for="i in date">
      <td>
        <img :src="'http://127.0.0.1:8000'+i.pict" alt="" width="100px">
      </td>
      <td><a :href=i.jump>跳转</a></td>
      <td>{{i.type}}</td>
    </tr>
  </table>
  <button v-for="i in asd" @click="get_show(i)">{{i}}</button>

</div>
</template>

<script>
export default {
  name: "p5_add",
  data(){
    return{
      form:{},
      show:{},
      date:{},
      num:"",
      asd:""
    }
  },
  methods:{
    get_add(){
      this.$axios.post('advertising/',this.form)
        .then(res=>{
          if (res.data.code==200){
            console.log(res.data)
            alert('添加成功')
            this.form={}
          }
          else {
            alert('添加失败')
          }
        })
    },
    get_get(i){
      this.$axios.get('journalism/?page='+i)
        .then(res=>{
          console.log(res.data)
          this.show = res.data.list
          this.num = res.data.num
        })
    },

    get_jia(){
      let fordata = new FormData()
      let pic = document.getElementById('img').files[0]
      fordata.append('jump',this.form.jump)
      fordata.append('pict',pic)
      fordata.append('type',this.form.type)
      this.$axios.post('advertising/',fordata)
      .then(res=>{
        console.log(res.data)
      })
    },
    get_show(i){
      this.$axios.get('advertising/?page='+i)
      .then(res=>{
        console.log(res.data)
        this.date = res.data.list
        this.asd = res.data.num
      })
    }
  },
  mounted() {
    this.get_show(1)
  }

}
</script>

<style scoped>

</style>
